<?php
	include_once 'config.inc.php';//导入配置文件
	//读取分类
//	session_start();//开启session会话
//	const DSN = 'mysql:host=localhost;dbname=kpshop';
//	const DBUSER = 'root';
//	const DBPWD = 'root';
//	$pdo = new PDO(DSN, DBUSER, DBPWD);
//	$uid = empty($_SESSION['uid']) ? 0 : $_SESSION['uid'];//用户登陆ID
	//echo $uid;
	//print_r($_SESSION);
	//================================================================
	$stmt = $pdo->prepare("select id,cid,pid,cname from kp_goods_class where state = 1 and (pid is null or pid = '') order by cid asc");
	$stmt->execute();//如有参传数组
	$classArr = $stmt->fetchAll(PDO::FETCH_ASSOC);//得到数组:返回一级分类
	//print_r($classArr);
?>
<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>贵美商城</title>
		<link rel="stylesheet" type="text/css" href="css/header.css"/>
		<script src="js/header.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div class="header">
			<ul class="menu">
				<li class="pci1"></li>
				<li>
					<a href="<?php if($uid >0) echo 'carlist.php'; else echo 'login.php'; ?>">购物车</a>
				</li>
				<li class="pci2"></li>
				<li>
					<a href="uorders.php">订单中心</a>
				</li>
				<li class="pci3"></li>
				<li>
					<a href="javascript:void(0)" onclick="AddFavorite(window.location,document.title)">加入收藏</a>
				</li>
				<li class="pci4"></li>
				<li>
					<!--<a href="javascript:void(0)" onclick="SetHome(this,window.location)">设为首页</a>-->
					<a href="userinfo.php">用户中心</a>
					
				</li>
				<li class="bt">
				<?php
					if($uid != 0){
						echo '<a href="logout.php">注销</a>';
					}else{
						echo '<a href="login.php">登陆</a>';
					}
				?>
					<!--<a href="login.php">登陆</a>-->
				</li>
				<li class="bt">
					<a href="reg.php">注册</a>
				</li>
			</ul>
			<div class="welcome">
				<?php
					if($uid != 0){
						echo $_SESSION['uname'];
					}
				?>
					你好,欢迎访问贵美商城!
			</div>
			<ul class="nav">
				<li id="show_nav">
					<a href="goodslist.php">☰贵美分类 ></a>
					<!--分类开始-->
					<ul id="show_nav1">
						<?php  foreach($classArr as $class){?>
						
						<li class="h3">
							<!--一级分类-->
							<a href="<?php echo 'goodslist.php?cid='.$class['cid']; ?>"><h3><?php echo $class['cname']; ?></h3></a>
							<!--开始输出二级菜单-->
							<?php  
								$stmt1 = $pdo->prepare("select id,cid,pid,cname from kp_goods_class where state = 1 and pid = ? order by cid asc");
								$stmt1->execute(array($class['cid']));//如有参传数组
								$classArr1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);//得到数组:返回二级分类
								//print_r($classArr);
								//如果二级分类不为空,则输出它
								if(!empty($classArr1)){
									echo '<ul class="show_nav2">';
									foreach($classArr1 as $class2){
										echo '<a href="'.'goodslist.php?cid='.$class2['cid'].'"><li>'.$class2['cname'].'</li></a>';
									}									
									echo '</ul>';
								}
							?>
							<!--<ul class="show_nav2">
								<a href="#"><li>美容1</li></a>
								<a href="#"><li>美容2</li></a>
								<a href="#"><li>美容3</li></a>
								<a href="#"><li>美容4</li></a>
							</ul>-->
						</li>
						<?php } ?>
					</ul>
					<!--分类结束-->
				</li>
				<li>
					<a href="index.php">
						首页
					</a>
				</li>
				<li><a href="news.php">资讯</a></li>
				<li>
					<a href="help.php">
						帮助中心
					</a>
				</li>
				<li class="right">
					<input type="text"  id="search" value="" placeholder="请输入搜索内容" />
				<!--</li>
				<li class="right">-->
					<input type="button"  id="searchgo" onclick="location.href='goodslist.php?search='+document.querySelector('#search').value" value="搜索" />
				</li>
			</ul>

		</div>
		<!--☰&nbsp;MENU-->
	</body>

</html>